<template>
	<view>
		<zmm-watermark :watermark="userStore.watermark" v-if="userStore.watermark"></zmm-watermark>
		<view class="content detail">
			<!--仓库信息-->
			<view class="detail-item">
				<uni-section title="仓库信息" type="line"></uni-section>
				<view class="detail-content">
					<view class="detail-text">
						仓库名称：
						<text>{{info.name}}</text>
					</view>
					<view class="detail-text">
						仓库编码：
						<text>{{info.code}}</text>
					</view>
					<view class="detail-text">
						区域：
						<uni-tag size="small" :text="arrText(setStore.allProvinceList, info.regionCode)" />
					</view>
					<view class="detail-text">
						联系方式：
						<text>{{info.phone}}</text>
						<text class="detail-text-copy" @click="copyText(info.phone)">复制</text>
						<text class="detail-text-copy" @click="call(info.phone)">拨打</text>
					</view>
					<view class="detail-text">
						父仓库：
						<text>{{info.parentName}}</text>
					</view>
					<view class="detail-text">
						系统用户：
						<text>{{info.userName}}</text>
						<text class="detail-text-copy" @click="copyText(info.userName)">复制</text>
					</view>
					<view class="detail-text">
						仓库类型：
						<text>{{arrText(warehouseTypeList, info.type)}}</text>
					</view>
					<view class="detail-text">
						仓库地址：
						<text>{{info.addr}}</text>
					</view>
					<view class="detail-text">
						状态：
						<uni-tag size="small" :type="info.status === 0 ? 'success' : ''" :text="arrText(warehouseStatusList, info.status)" />
					</view>
				</view>
			</view>
			
		</view>
	</view>
</template>

<script setup>
import { onLoad } from '@dcloudio/uni-app';
import { computed, onMounted, ref } from 'vue';
import { tab, auth, modal } from "@/plugins"
import { getTitle } from "@/utils/getter"
import { checkPermi, checkRole, checkOnlyPermi, checkOnlyRole } from "@/utils/permission"
import { warehouseDetail } from "@/api/erp_api/warehouse"
import { allProvince } from "@/api/erp_api/region"
import { warehouseType } from "@/api/system/dict/data"
import { copyText, arrText, previewImg } from '@/utils/ty.js';
import useUserStore from '@/store/modules/user'
import useSetStore from '@/store/modules/set'
import { warehouseStatusList } from '@/utils/config.js'

	const userStore = useUserStore()
	const setStore = useSetStore()
	onLoad((option) => {
		if (option.id) {
			id.value = option.id
			getDetail()
		}
	})
	
	// 获取仓库类型
	const warehouseTypeList = ref([])
	const getWarehouseType = () => {
		return warehouseType().then(res => {
			warehouseTypeList.value = res.data.map(item => {
				return {
					...item,
					value: item.dictValue,
					text: item.dictLabel
				}
			}) || []
		})
	}
	
	// 数据查询
	const id = ref('')
	const info = ref({})
	const isLoading = ref(false)
	
	const getDetail = () => {
		const params = {
			id: id.value
		}
		isLoading.value = true
		uni.showLoading({
			title: '数据加载中...'
		})
		warehouseDetail(params).then(res => {
			info.value = res.data || {}
			isLoading.value = false
			uni.hideLoading()
    }).catch(() => {
			isLoading.value = false
			uni.hideLoading()
		})
	}
	
	// 拨打电话
	const call = (phone) => {
		uni.makePhoneCall({
			phoneNumber: phone
		})
	}
	
	onMounted(() => {
		getWarehouseType()
	})
	
</script>

<style scoped lang="scss">
</style>
